package tute;


import cartas.Naipe;
import cartas.mazo;
import java.util.ArrayList;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author robertorosas
 */
public class CombinationHelper {

    public CombinationHelper(){
        
        
    }
    
    
    public ArrayList<mazo> getCombinations(mazo Deck,int comb_size){
        
          ArrayList<mazo> result = new ArrayList();
          mazo temp ;
          
            int[] indices;
         CombinationGenerator mygenerator = new CombinationGenerator(Deck.getSize(),comb_size);
         
       
        
         
        while (mygenerator.hasMore ()) {
        temp = new mazo();
        indices = mygenerator.getNext ();
       for (int i = 0; i < indices.length; i++) {
          temp.anadirNaipe(Deck.getNaipe(indices[i]));
          
        }
        
       result.add(temp);
         
          }
         
         return result;
         
        } 
    public double[]  CardVsCombinations(mazo Hand,ArrayList<mazo> combinations,String vida){
         double count=0;
         double comb_size = combinations.size();
         double[] probability = new double[Hand.getSize()];
         Naipe currentNaipe;
         for (int i=0;i<Hand.getSize();i++){
             count=0;
             currentNaipe= Hand.getNaipe(i);
                              for (int j=0;j<comb_size;j++){
                 
                     if(isWinner(vida,combinations.get(j),currentNaipe,true)){
                     
                     count++;
                     
                 }
                 
                 
             }
             
             probability[i]=(count/comb_size);
             
             
             
             
             
         }
        
        
        
        return probability ;
    }        
             
             
         
         
    
    


private boolean isWinner(String vida,mazo tripleta,Naipe carta, boolean turn){
     Naipe temp = new Naipe();
    for (int i=0;i<tripleta.getSize();i++){
        
       temp=tripleta.sacarNaipe(i);
      if((temp.nombreFlor()!=vida)&&(carta.nombreFlor()==vida)){
          
           return true;
           
      } else if(temp.nombreFlor()!=carta.nombreFlor()){
          
          if(!turn){
          return true;
          } else{
              return false;
          }
      } else {
                 
          return carta.valor()>=temp.valor();
          
      }
       
    
          
        
    }
     
     return false;
    
    
}
    
}
